//
//  SecViewController.m
//  HomeFurnishing
//
//  Created by dllo on 16/4/7.
//  Copyright © 2016年 YMing. All rights reserved.
//

#import "SecViewController.h"
#import "StyTableViewCell.h"
#import "StyBaseModel.h"
#import "DetailStyVC.h"
@interface SecViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic, retain)UITableView *tableV;
@property(nonatomic, retain)NSArray *dataArr;
@end

@implementation SecViewController

-(void)dealloc
{
    [_tableV release];
    [_num release];
    [_dataArr release];
    [_name release];
    [super dealloc];
}
-(NSString *)segmentTitle
{
    return [NSString stringWithFormat:@"%@ 攻略",self.num];
}
-(UIScrollView *)streachScrollView
{
    return self.tableV;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor yellowColor];
    self.dataArr = [NSArray array];
    self.tableV = [[UITableView alloc] initWithFrame:self.view.frame style:(UITableViewStylePlain)];
    self.tableV.delegate = self;
    self.tableV.dataSource = self;
    self.tableV.rowHeight = 170;
    [self.view addSubview:self.tableV];
    [_tableV release];
    [self.tableV registerClass:[StyTableViewCell class] forCellReuseIdentifier:@"SecVCTableVCell"];
    [self dataHandle];
}

-(void)dataHandle
{
    NSString *str = [NSString stringWithFormat:@"http://api.guju.com.cn/v2/user/%@/strategy?start=0&count=5&checked=1&loginId=0",self.name];
    NSString *newStr = [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
    [NetworkHandle GetDataWithURL:newStr dic:nil success:^(id responseObject) {
        self.dataArr = [StyBaseModel transformWithArray:responseObject[@"strategyList"]];
        [self.tableV reloadData];
    } filed:^(NSError *error) {
        
    }];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    StyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SecVCTableVCell" forIndexPath:indexPath];
    StyBaseModel *m = _dataArr[indexPath.row];
    cell.title.text = m.title;
    cell.details.text = m.descrip;
    cell.style.text = m.categoryName;
    NSString *str = [NSString stringWithFormat:@"http://gooju.cn/dimages/%@_0_w640_h0_m0.jpg",m.covorPhotoId];
    [cell.imgView sd_setImageWithURL:[NSURL URLWithString:str]];

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailStyVC *VC = [[DetailStyVC alloc] init];
    StyBaseModel *m = _dataArr[indexPath.row];
    VC.mId = m.mId;
    [self.navigationController pushViewController:VC animated:YES];
    [VC release];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
